package com.cloud.system.api.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.system.api.bean.HumanRoleForm;
import com.cloud.system.api.bean.HumanRoleResourcesForm;
import com.cloud.system.api.entity.RoleInfo;
import com.cloud.system.api.service.RoleInfoService;
import com.cloud.system.common.result.Quokka;

@RestController
@RequestMapping("/system/api/roleinfo")
public class RoleInfoController {

	@Autowired
	private RoleInfoService roleInfoService;

	@RequestMapping("listtree")
	public Quokka listTree(long unitId, boolean isRoot) {
		return new Quokka(true, roleInfoService.listRoleTree(unitId, isRoot));
	}

	@RequestMapping("search")
	public Quokka search(String name) {
		return new Quokka(true, roleInfoService.search(name));
	}

	@RequestMapping("findrolesbyunitid")
	public Quokka findRolesByUnitId(long id) {
		return new Quokka(true, roleInfoService.findRolesByUnitId(id));
	}

	@RequestMapping("load")
	public Quokka load(long id) {
		return new Quokka(true, roleInfoService.load(id));
	}

	@RequestMapping("showadd")
	public Quokka showAdd(long unitId) {
		return new Quokka(true, roleInfoService.showAdd(unitId));
	}

	@RequestMapping("saveupdate")
	public Quokka saveUpdate(@RequestBody(required = true) RoleInfo role) {
		return new Quokka(true, roleInfoService.saveUpdateRole(role));
	}
	
	@RequestMapping("delete")
	public Quokka delete(long roleId) {
		return new Quokka(true, roleInfoService.delete(roleId));
	}
	
	@RequestMapping("gethumanbyrole")
	public Quokka getHumanByRole(long roleId){
		return new Quokka(true, roleInfoService.getHumanByRole(roleId));
	}
	
	@RequestMapping("saveupdaterolehuman")
	public Quokka saveUpdateRoleHuman(@RequestBody(required = true) HumanRoleForm form){
		return new Quokka(true, roleInfoService.saveUpdateRoleHuman(form));
	}
	
	@RequestMapping("loadroleresources")
	public Quokka loadRoleResources(long roleId){
		return roleInfoService.loadRoleResources(roleId);
	}
	
	@RequestMapping("saveupdateroleresources")
	public Quokka saveUpdateRoleResources(@RequestBody(required = true) HumanRoleResourcesForm form){
		return new Quokka(true, roleInfoService.saveUpdateRoleResources(form));
	}
}
